
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>KBase模块 &#8212; PyKBase 2.0.0 文档</title>
    <link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/language_data.js"></script>
    <script type="text/javascript" src="_static/translations.js"></script>
    <link rel="index" title="索引" href="genindex.html" />
    <link rel="search" title="搜索" href="search.html" />
    <link rel="next" title="connection类" href="connection.html" />
    <link rel="prev" title="欢迎使用PyKBase帮助文档" href="index.html" />
   
  <link rel="stylesheet" href="_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <div class="section" id="kbase">
<h1>KBase模块<a class="headerlink" href="#kbase" title="永久链接至标题">¶</a></h1>
<span class="target" id="module-KBase"></span><p>KBase接口模块是依据DB API 2.0规范编写而来.该模块基本实现了DB API 2.0的各个部分,如连接对象,游标对象,以及TPIClient的各个接口.由于KBase不支持事务,所以暂未实现commit()、rollback()等与事务相关的接口.</p>
<p>在DB API 2.0规范中定义了一个非常重要的方法–connect()方法,通过实现该方法就可以生成一个connection对象,进而访问数据库.</p>
<dl class="function">
<dt id="KBase.connect">
<code class="sig-prename descclassname">KBase.</code><code class="sig-name descname">connect</code><span class="sig-paren">(</span><em class="sig-param">host = &quot;127.0.0.1&quot;</em>, <em class="sig-param">port = 4567</em>, <em class="sig-param">user = &quot;DBOWN&quot;</em>, <em class="sig-param">passwd = &quot;&quot;</em><span class="sig-paren">)</span><a class="headerlink" href="#KBase.connect" title="永久链接至目标">¶</a></dt>
<dt>
<code class="sig-prename descclassname">KBase.</code><code class="sig-name descname">connect</code><span class="sig-paren">(</span><em class="sig-param">&quot;127.0.0.1&quot;</em>, <em class="sig-param">4567</em>, <em class="sig-param">&quot;DBOWN&quot;</em>, <em class="sig-param">&quot;&quot;</em><span class="sig-paren">)</span></dt>
<dt>
<code class="sig-prename descclassname">KBase.</code><code class="sig-name descname">connect</code><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd><p>创建并返回一个连接对象</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">KBase</span>

<span class="c1">#DSN形式参数</span>
<span class="n">conn</span> <span class="o">=</span> <span class="n">KBase</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">host</span> <span class="o">=</span> <span class="s2">&quot;127.0.0.1&quot;</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="mi">4567</span><span class="p">,</span> <span class="n">user</span> <span class="o">=</span> <span class="s2">&quot;DBOWN&quot;</span><span class="p">,</span> <span class="n">passwd</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;connection handle is:&#39;</span><span class="p">,</span> <span class="n">conn</span><span class="o">.</span><span class="n">hcon</span><span class="p">)</span><span class="c1">#connection handle is: 1025</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;connection errcode is:&#39;</span><span class="p">,</span> <span class="n">conn</span><span class="o">.</span><span class="n">errcode</span><span class="p">)</span><span class="c1">#connection errcode is: 0</span>
<span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="c1">#以多个位置参数的形式</span>
<span class="n">conn</span> <span class="o">=</span> <span class="n">KBase</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s2">&quot;127.0.0.1&quot;</span><span class="p">,</span> <span class="mi">4567</span><span class="p">,</span> <span class="s2">&quot;DBOWN&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;connection handle is:&#39;</span><span class="p">,</span> <span class="n">conn</span><span class="o">.</span><span class="n">hcon</span><span class="p">)</span><span class="c1">#connection handle is: 1026</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;connection errcode is:&#39;</span><span class="p">,</span> <span class="n">conn</span><span class="o">.</span><span class="n">errcode</span><span class="p">)</span><span class="c1">#connection errcode is: 0</span>
<span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="c1">#使用默认参数</span>
<span class="n">conn</span> <span class="o">=</span> <span class="n">KBase</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;connection handle is:&#39;</span><span class="p">,</span> <span class="n">conn</span><span class="o">.</span><span class="n">hcon</span><span class="p">)</span><span class="c1">#connection handle is: 1027</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;connection errcode is:&#39;</span><span class="p">,</span> <span class="n">conn</span><span class="o">.</span><span class="n">errcode</span><span class="p">)</span><span class="c1">#connection errcode is: 0</span>
<span class="n">conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
<p>连接函数参数表示:</p>
<ul class="simple">
<li><p>host – 服务器IP</p></li>
<li><p>port – 通信端口</p></li>
<li><p>user – 用户名称</p></li>
<li><p>passwd – 用户密码</p></li>
</ul>
</dd></dl>

</div>


          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html">PyKBase</a></h1>








<h3>导航</h3>
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">KBase模块</a></li>
<li class="toctree-l1"><a class="reference internal" href="connection.html">connection类</a></li>
<li class="toctree-l1"><a class="reference internal" href="cursor.html">cursor类</a></li>
<li class="toctree-l1"><a class="reference internal" href="TPIClient.html">TPIClient类</a></li>
<li class="toctree-l1"><a class="reference internal" href="TPIClient_Struct.html">TPIClient_Struct内容</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="index.html">Documentation overview</a><ul>
      <li>Previous: <a href="index.html" title="上一章">欢迎使用PyKBase帮助文档</a></li>
      <li>Next: <a href="connection.html" title="下一章">connection类</a></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="转向" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2019, ZZJ.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 2.2.2</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
      |
      <a href="_sources/kbasemodule.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>